<?php
session_start();
require_once('session.php');
require_once '../sql/connection.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
<?php

if ($_POST['name'] == "") {
    echo "<script>alert('标题不能为空!');history.go(-1)</script>";
    exit;
}

if ($_POST['image'] == "") {
    echo "<script>alert('宣传图不能为空!');history.go(-1)</script>";
    exit;
}
if ($_POST['introduction'] == "") {
    echo "<script>alert('描述不能为空!');history.go(-1)</script>";
    exit;
}

/*处理推荐位数据开始*/
if ($_POST['posid'] <> "") {
    foreach ($_POST['posid'] as $i) {
        $posid .= $i . ",";
    }
    $posid = substr($posid, 0, -1);
} else {
    $posid = "";
}
/*处理推荐位数据结束*/

$name = $_POST['name'];
$stock = $_POST['stock'];
$price = $_POST['price'];
$image = $_POST['image'];
$series_id = $_POST['series_id'];
$introduction = $_POST['introduction'];
$sql = "INSERT INTO commodity (name,stock,price,image,series_id,introduction) 
values ('$name',$stock,$price,'$image',$series_id,'$introduction')";
//mysqli_query($GLOBALS['conn'], $sql);
if (mysqli_query($GLOBALS['conn'], $sql)) {
    echo "<script>alert('数据写入成功！');window.location.href='produce_add.php';</script>";
} else {
    echo "<script>alert('数据写入失败！');window.location.href='produce_add.php';</script>";
}
mysqli_close($GLOBALS['conn']);
?>
</body>
</html>